package com.itheima.controller.v1;


import com.itheima.common.R;
import com.itheima.controller.v1.api.TbBusinessControllerApi;
import com.itheima.dto.BusinessQueryDto;
import com.itheima.pojo.TbBusiness;
import com.itheima.service.TbBusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/*
 *@Parm
 *@ClassName TbBusinessController
 *@Date 2022/1/17 17:20
 */
@CrossOrigin
@RestController
@RequestMapping("/business")
public class TbBusinessController implements TbBusinessControllerApi {
    @Autowired
    private TbBusinessService businessService;

    @PostMapping
    @Override
    public R addBusiness(@RequestBody TbBusiness tbBusiness) {
        if(tbBusiness == null){
            return R.error("参数异常");
        }
        R r = businessService.add(tbBusiness);
        return r;
    }

    @GetMapping("/list")
    @Override
    public R selectPage(BusinessQueryDto businessQueryDto) {
        if(businessQueryDto == null){
            return R.error("参数异常");
        }
       R r = businessService.selectPage(businessQueryDto);
        return r;
    }

    @Override
    @GetMapping("/treelist")
    public R Assign() {
        R r = businessService.assign();
        return r;
    }

    @Override
    @GetMapping("/{id}")
    public R AssignChioce(@PathVariable Long id) {
        R r =businessService.selectById(id);
        return r;
    }

    @Override
    @PostMapping("/subject")
    public R subject() {
        R r = businessService.subject();
        return r;
    }

    @Override
    @PutMapping
    public R modify(@RequestBody TbBusiness business) {
        R r = businessService.modify(business);
        return r;
    }

    @Override
    public R gain(Long[] ids) {
        if (ids.length > 3){
            return R.error("保有量达到上限");
        }

        return null;
    }


}
